package com.godchicken.praise_each_other.cim.server.serviceImpl;

import com.godchicken.praise_each_other.cim.server.constant.MsgConStant;
import com.godchicken.praise_each_other.cim.server.constant.StatusConstant;
import com.godchicken.praise_each_other.cim.server.entity.Result;
import com.godchicken.praise_each_other.cim.server.mapper.UserMapper;
import com.godchicken.praise_each_other.cim.server.pojo.User;
import com.godchicken.praise_each_other.cim.server.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * com.godchicken.praise_each_other.cim.server.serviceImpl
 * 2020/11/13
 *
 * @author: godchicken
 */
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Result doLogin(User user) {
        Result result = new Result();
        User returnUser = userMapper.selectByUserAccount(user.getUserAccount());
        if(returnUser != null) {

            if (returnUser.getUserPassword().equals(user.getUserPassword())) {
                result.setMsg(MsgConStant.LOGIN_SUCCESS);
                result.setStatus(StatusConstant.SUCCESS);
                //清空返回的密码，以防前端可以拿到
                returnUser.setUserPassword("");
                result.addData("user", returnUser);
            } else {
                result.setMsg(MsgConStant.LOGIN_FAILED);
                result.setStatus(StatusConstant.FAILED);
            }
        }else {
            result.setMsg(MsgConStant.LOGIN_FAILED);
            result.setStatus(StatusConstant.FAILED);
        }

        return result;
    }

}
